package com.example.mytestdemo.view.camera3dapplication

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.example.mytestdemo.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class Camera3dActivity : AppCompatActivity() {
    lateinit var btn_pre1: Button
    lateinit var btn_next1: Button
   lateinit var camera3DView1: Camera3DView
    lateinit  var camera3DView2: Camera3DView
    lateinit  var camera3DView3: Camera3DView
    lateinit  var camera3DView4: Camera3DView
    lateinit  var camera3DView5: Camera3DView
    lateinit  var camera3DView6: Camera3DView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main_camera_3d)

        btn_pre1 = findViewById(R.id.btn_pre1)
        btn_next1 = findViewById(R.id.btn_next1)
        camera3DView1 = findViewById(R.id.camera3DView1)
        camera3DView2 = findViewById(R.id.camera3DView2)
        camera3DView2.setOrientation(Camera3DView.HORIZONTAL)

//        camera3DView1.addResId(R.drawable.img1)
//        camera3DView1.addResId(R.drawable.img2)
//        camera3DView1.addResId(R.drawable.img3)
//        camera3DView1.addResId(R.drawable.cat)
        camera3DView1.addResId(R.drawable.ce)
        camera3DView1.addResId(R.drawable.zhen)
        camera3DView1.addResId(R.drawable.ce)
        camera3DView1.addResId(R.drawable.bei)

        camera3DView2.addResId(R.drawable.ce)
        camera3DView2.addResId(R.drawable.zhen)
        camera3DView2.addResId(R.drawable.ce)
        camera3DView2.addResId(R.drawable.bei)

//        camera3DView2.addResId(R.drawable.img1)
//        camera3DView2.addResId(R.drawable.img2)
//        camera3DView2.addResId(R.drawable.img3)

        //--------------百叶窗
        camera3DView3 = findViewById(R.id.camera3DView3)
        camera3DView4 = findViewById(R.id.camera3DView4)
        camera3DView4.setOrientation(Camera3DView.HORIZONTAL)
        camera3DView3.addResId(R.drawable.img1)
        camera3DView3.addResId(R.drawable.img2)
        camera3DView3.addResId(R.drawable.img3)
        camera3DView4.addResId(R.drawable.img1)
        camera3DView4.addResId(R.drawable.img2)
        camera3DView4.addResId(R.drawable.img3)

        //--------------滚动
        camera3DView5 = findViewById(R.id.camera3DView5)
        camera3DView6 = findViewById(R.id.camera3DView6)
        camera3DView6.setOrientation(Camera3DView.HORIZONTAL)
        camera3DView5.addResId(R.drawable.img1)
        camera3DView5.addResId(R.drawable.img2)
        camera3DView5.addResId(R.drawable.img3)
        camera3DView6.addResId(R.drawable.img1)
        camera3DView6.addResId(R.drawable.img2)
        camera3DView6.addResId(R.drawable.img3)

        btn_next1.setOnClickListener(View.OnClickListener {
            lifecycleScope.launch(Dispatchers.IO) {
                while (true) {
                    delay(1100)
                    withContext(Dispatchers.Main) {
                        camera3DView2.next()

//                        camera3DView3.next()
//                        camera3DView4.next()
//
//                        camera3DView5.next()
//                        camera3DView6.next()
                    }
                }
            }
        })
        btn_pre1.setOnClickListener(View.OnClickListener {
            lifecycleScope.launch(Dispatchers.IO) {
                while (true){
                    delay(1100)
                    withContext(Dispatchers.Main) {
                        camera3DView1.pre()
//                        camera3DView2.pre()
//
//                        camera3DView3.next()
//                        camera3DView4.next()
//
//                        camera3DView5.next()
//                        camera3DView6.next()
                    }

                }
            }

        })
    }
}
